/********************************
* namespaces
*********************************/
var Narti = Narti || {};
Narti.Canvas = Narti.Canvas || {};

/********************************
* constructor
*********************************/
Narti.Canvas.Audio = function(file){
	var _this = this;
	
	this.audio = document.createElement("audio");
	this.audioType = this.getAudioType(this.audio);
	if(this.audioType.lenght == 0)return;

	this.sone = true;
	this.audio.volume = 0.5;
	this.mLoadCount = 1;
	
	
	this.audio.setAttribute("src", file + "." + this.audioType);
	this.audio.addEventListener("canplaythrough", _this.start, false);
}




Narti.Canvas.Audio.prototype = {
	start: function() {
		if (--this.mLoadCount > 0) return;
		
		this.play();
	},
	play: function(){
		this.audio.play();
		this.sone = true;		
	},
	pause: function(){
		this.audio.pause();
		this.sone = false;		
	},
	toggle: function(){
		if( this.sone){
			this.pause();
		}else{
			this.play();
		}
	},
	getAudioType : function(elem) {
		
		var extension = "";
		if(elem.canPlayType('audio/ogg; codecs="vorbis"')){
			extension =  "ogg";
		}else if (elem.canPlayType('audio/mpeg;')){
			extension = "mp3";
		}else if(elem.canPlayType('audio/wav; codecs="1"')){
			extension = "wav";
		}
		console.log(extension);
        return extension;
    }
	
	
};

